package com.laoniu.service.sys;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laoniu.dto.request.RoleRequestDto;
import com.laoniu.mapper.SysRoleMapper;
import com.laoniu.entity.SysRole;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RoleService extends ServiceImpl<SysRoleMapper, SysRole> {

    @Resource
    private SysRoleMapper roleMapper;

    public Page<SysRole> pageList(RoleRequestDto dto){
        Page<SysRole> sysRolePage = new Page<>(dto.getPageNo(), dto.getPageSize());
        LambdaQueryWrapper<SysRole> wrapper = Wrappers.lambdaQuery(SysRole.class);
        wrapper.like(StringUtils.isNotBlank(dto.getName()), SysRole::getName , dto.getName());
        wrapper.orderByDesc(SysRole::getId);
        return roleMapper.selectPage(sysRolePage,wrapper);
    }

}
